package com.mdd.common.wechat.utils;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;

/**
 * @ClassName:StreamUtils
 * @Author:lrc
 * @Date:2022/9/30 上午10:08
 * @Desc: 请求中获取参数
 * @Version:1.0
 */
public class StreamUtils {

    public static String inputStream2String(InputStream in, String encoding) {
        String result = null;
        try {
            if (in != null) {
                ByteArrayOutputStream os = new ByteArrayOutputStream();
                byte[] tempBytes = new byte[4096];
                int count = -1;
                while ((count = in.read(tempBytes, 0, 4096)) != -1) {
                    os.write(tempBytes, 0, count);
                }
                tempBytes = null;
                os.flush();
                result = new String(os.toByteArray(), encoding);
            }
        } catch (Exception e) {
            result = null;
        }
        return result;
    }

}
